package com.example.redistest.controller;

import com.example.redistest.pojo.TokenInfo;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.time.LocalDateTime;

@RestController()
@RequestMapping("test")
public class TestController {


    @Resource
    private StringRedisTemplate stringRedisTemplate;

    String key1="dms:auth:session:6330c842-0fdd-4042-9763-484a2991b3dd";


    @RequestMapping("aa")
    public TokenInfo tokenInfo() {
        TokenInfo tokenInfo = new TokenInfo();
        tokenInfo.setExpires_in(10);
        tokenInfo.setExpireTime(LocalDateTime.now());


        stringRedisTemplate.opsForValue().get(key1);


        return tokenInfo;
    }


    public static void main(String[] args) {
        String aa = "\\xAC\\xED\\x00\\x05sr\\x00+com.shein.common.security.config.DmsSession\\xBD\\xFCF\\xA0\\x8E\\x06\\x84S\\x02\\x00\\x00xr\\x00*org.apache.shiro.session.mgt.SimpleSession\\x9D\\x1C\\xA1\\xB8\\xD5\\x8Cbn\\x03\\x00\\x00xpw\\x02\\x00\\x1Bt\\x00$001c8ec3-d207-4c50-a7c8-904d129c907csr\\x00\\x0Ejava.util.Datehj\\x81\\x01KYt\\x19\\x03\\x00\\x00xpw\\x08\\x00\\x00\\x01\\x81>\\x9D\\xF0+xq\\x00~\\x00\\x05w\\x08\\x00\\x00\\x00\\x00\\x00\\xA4\\xCB\\x80x";

        Object o = byteToObject(aa.getBytes());
        System.out.println(o);

    }


    private static Object byteToObject(byte[] bytes) {
        java.lang.Object obj = null;
        try {
            //bytearray to object
            ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
            ObjectInputStream oi = new ObjectInputStream(bi);

            obj = oi.readObject();

            bi.close();
            oi.close();
        } catch (Exception ae) {
            System.out.println(ae);
        }
        return obj;
    }


}
